﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
using System.Text;
using Authorit.API.Dto;
using System.Reflection;

namespace ShowDependencies
{
    public class ObjectSummaryCollection : KeyedCollection<int,ObjectSummary>
    {
        #region Constructors (1) 

        public ObjectSummaryCollection() : base() { }

        #endregion Constructors 

        #region Methods (2) 

        // Public Methods (1) 

        public ObjectSummary GetItemByIndex(int index)
        {
            return this.Items[index];
        }
        // Protected Methods (1) 

        protected override int GetKeyForItem(ObjectSummary item)
        {
            return item.ObjectId;
        }

        #endregion Methods 
    }

    public class ObjectSummary : ObjectBrief
    {
        #region Fields (6) 

        private int inBookId;
        private bool isVariantParent;
        private string releaseStateName;
        private string topicText;
        private int wordCountResolved;
        private int wordCountUnresolved;
        private Color backgroundColor;
        private Color foregroundColor;
        #endregion Fields 

        #region Constructors (2) 

        public ObjectSummary(ObjectBrief objBrief)
        {
            foreach (PropertyInfo pi in objBrief.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                this.GetType().GetProperty(pi.Name).SetValue(this, pi.GetValue(objBrief, null), null);
            }
            Initialize();
        }

        private void Initialize()
        {
            this.releaseStateName = string.Empty;
            this.inBookId = -1;
            this.wordCountResolved = 0;
            this.wordCountUnresolved = 0;
            this.topicText = String.Empty;
        }

        public ObjectSummary()
        {
            Initialize();
        }

        #endregion Constructors 

        #region Properties (6) 

        public Color BackgroundColor
        {
            get { return backgroundColor; }
            set { backgroundColor = value; }
        }

        public Color ForegroundColor
        {
            get { return foregroundColor; }
            set { foregroundColor = value; }
        }

        public int InBookId
        {
            get { return inBookId; }
            set { inBookId = value; }
        }

        public bool IsVariantParent
        {
            get { return isVariantParent; }
            set { isVariantParent = value; }
        }

        public string ReleaseStateName
        {
            get { return releaseStateName; }
            set { releaseStateName = value; }
        }

        public string TopicText
        {
            get { return topicText; }
            set { topicText = value; }
        }

        public int WordCountResolved
        {
            get { return wordCountResolved; }
            set { wordCountResolved = value; }
        }

        public int WordCountUnresolved
        {
            get { return wordCountUnresolved; }
            set { wordCountUnresolved = value; }
        }

        #endregion Properties 

        #region Methods (3) 

        // Public Methods (3) 

        public Dictionary<string,string> GetPropertiesDictionary()
        {
            Dictionary<string, string> myProperties = new Dictionary<string, string>();
            Type t = this.GetType();
            foreach (PropertyInfo pi in t.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (null == (pi.GetValue(this, null)))
                {
                    myProperties.Add(pi.Name, String.Empty);
                }
                else
                { 
                myProperties.Add(pi.Name, pi.GetValue(this, null).ToString());
                }
            }
            return myProperties;
        }

        public string[] GetPropertyNamesArray()
        {
            return GetPropertiesDictionary().Keys.ToArray();
        }

        public string[] GetPropertyValuesArray()
        {
            return GetPropertiesDictionary().Values.ToArray();
        }

        #endregion Methods 
    }
}
